import socket
import config
import traceback
import datetime
#import sys

#HOST = sys.argv[1]
#PORT= int(sys.argv[2])

dataconf = config.read_config()
HOST = str(dataconf.setting[0].debug_host_client).strip()
#print "HOST = ", HOST
#HOST = "192.168.137.10"
PORT = int(str(dataconf.setting[0].debug_host_port).strip())
#PORT = 40000
#print "PORT = ", PORT
server_address = (HOST,int(PORT))

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind(server_address)

def getdatetime_now():
    dt = datetime.datetime.now()
    d2 = dt.strftime('%Y-%m-%d %H:%M:%S')
    return d2   

def start():
    while 1:
        try:
            message, address = s.recvfrom(8192)
            dtnow = getdatetime_now()
            mesg = re.split("\[|\]|,|'",str(message))
            msg_format = "%s --> %s - %s | %s"%(str(dtnow),str(mesg[2]).strip(),str(mesg[5]).strip(),str(address))
            print msg_format
        except(KeyboardInterrupt, SystemExit):
            raise
        except:
            import traceback
            traceback.format_exc()
    
    
    
    











